import request from '@/utils/request.js'

// 查询部署的流程
export function deployedList (data){
    let urlParam = objToUrlParam(data);
    if(urlParam != null && urlParam != '') {
        urlParam = '?' + urlParam;
    }

    return request({
        url:'/deploy/deployInfoPageList' + urlParam,
        method: 'get'
    })
}


function objToUrlParam(data) {
    if (!data) return '';

    return Object.keys(data)
        .filter(key => data[key] !== null && data[key] !== undefined && data[key] !== '')
        .map(key => encodeURIComponent(key) + '=' + encodeURIComponent(data[key]))
        .join('&');
}






// 保存部署的流程
export function saveDeployInfo (data){
    return request({
        url:'/deploy/saveDeployInfo',
        method: 'post',
        data: data
    })
}

// 部署流程
export function deploy (data){
    return request({
        url:'/deploy/deploy',
        method: 'post',
        data: data
    })
}

// 删除部署流程
export function deleteDeploy (data){
    return request({
        url:'/deploy/deleteDeploy',
        method: 'post',
        data: data
    })
}

// 下载部署文件流
export function downloadDeployStream (fileId){
    return request({
        url:'/deploy/downloadDeployStream/' + fileId,
        method: 'get',
        responseType: 'blob',
    })
}